/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import acc.AdministrationInteraction;
import gui.ShowMessageDialog;
import acc.DataInteraction;
import acc.LoginInteraction;
import acc.Validation;
import entity.User;
import java.awt.Color;
import java.sql.Date;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.JTextComponent;

/**
 *
 * @author Haitm
 */
public class CreateAccountDialog extends javax.swing.JDialog {

    /**
     * Creates new form CreateAccount
     */
    public CreateAccountDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        DataInteraction.configServer();
        setLocationRelativeTo(null);
        setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlAdmin = new javax.swing.JPanel();
        txtUserID = new javax.swing.JTextField();
        lblUserID = new javax.swing.JLabel();
        lblUserName = new javax.swing.JLabel();
        txtUserName = new javax.swing.JTextField();
        lblGroupName = new javax.swing.JLabel();
        lblGroupID = new javax.swing.JLabel();
        lblFullname = new javax.swing.JLabel();
        txtGroupID = new javax.swing.JTextField();
        txtFirstName = new javax.swing.JTextField();
        lblPassword = new javax.swing.JLabel();
        lblConfirmPass = new javax.swing.JLabel();
        cboGroupName = new javax.swing.JComboBox();
        txtConfirmPassword = new javax.swing.JPasswordField();
        txtPassword = new javax.swing.JPasswordField();
        jLabel1 = new javax.swing.JLabel();
        txtLastName = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtPhone = new javax.swing.JTextField();
        lblGroupName1 = new javax.swing.JLabel();
        cboPermisson = new javax.swing.JComboBox();
        lblGender = new javax.swing.JLabel();
        cboGender = new javax.swing.JComboBox();
        txtBirthDate = new javax.swing.JTextField();
        lblBirthday = new javax.swing.JLabel();
        lblEmail = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        txaAddress = new javax.swing.JTextArea();
        lblAddress = new javax.swing.JLabel();
        btnCreate = new javax.swing.JButton();
        btnRefresh = new javax.swing.JButton();

        setMinimumSize(new java.awt.Dimension(500, 700));
        setPreferredSize(new java.awt.Dimension(500, 700));

        pnlAdmin.setBackground(new java.awt.Color(255, 255, 255));
        pnlAdmin.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 103, 0)));
        pnlAdmin.setMinimumSize(new java.awt.Dimension(500, 700));
        pnlAdmin.setPreferredSize(new java.awt.Dimension(500, 700));

        txtUserID.setBackground(new java.awt.Color(240, 249, 255));
        txtUserID.setEditable(false);
        txtUserID.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txtUserID.setForeground(new java.awt.Color(3, 97, 145));
        txtUserID.setText("User01");
        txtUserID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtUserIDActionPerformed(evt);
            }
        });

        lblUserID.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblUserID.setText("User ID:");

        lblUserName.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblUserName.setText("User Name:");

        txtUserName.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        lblGroupName.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblGroupName.setText("Group Name:");

        lblGroupID.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblGroupID.setText("Group ID:");

        lblFullname.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblFullname.setText("FirstName:");

        txtGroupID.setBackground(new java.awt.Color(240, 249, 255));
        txtGroupID.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txtGroupID.setForeground(new java.awt.Color(3, 97, 145));
        txtGroupID.setText("Group01");

        txtFirstName.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        lblPassword.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblPassword.setText("Password:");

        lblConfirmPass.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblConfirmPass.setText("Confirm Pass:");

        cboGroupName.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        cboGroupName.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Administrator" }));
        cboGroupName.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        cboGroupName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboGroupNameActionPerformed(evt);
            }
        });

        txtConfirmPassword.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        txtPassword.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel1.setText("LastName:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel2.setText("Phone:");

        lblGroupName1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblGroupName1.setText("Permission: ");

        cboPermisson.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        cboPermisson.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Administrator" }));
        cboPermisson.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        cboPermisson.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboPermissonActionPerformed(evt);
            }
        });

        lblGender.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblGender.setText("Gender:");

        cboGender.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        cboGender.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Male", "Female" }));

        txtBirthDate.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        lblBirthday.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblBirthday.setText("Birdhday:");

        lblEmail.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblEmail.setText("Email:");

        txtEmail.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jScrollPane2.setBackground(new java.awt.Color(255, 255, 255));
        jScrollPane2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));

        txaAddress.setColumns(20);
        txaAddress.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txaAddress.setLineWrap(true);
        txaAddress.setRows(2);
        txaAddress.setWrapStyleWord(true);
        jScrollPane2.setViewportView(txaAddress);

        lblAddress.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblAddress.setText("Address:");

        btnCreate.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnCreate.setForeground(new java.awt.Color(3, 97, 145));
        btnCreate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/btn_add.png"))); // NOI18N
        btnCreate.setText("Create");
        btnCreate.setMargin(new java.awt.Insets(0, 1, 0, 1));
        btnCreate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCreateActionPerformed(evt);
            }
        });

        btnRefresh.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnRefresh.setForeground(new java.awt.Color(3, 97, 145));
        btnRefresh.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/btn_cancel.png"))); // NOI18N
        btnRefresh.setText("Refresh");
        btnRefresh.setMargin(new java.awt.Insets(0, 1, 0, 1));
        btnRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefreshActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlAdminLayout = new javax.swing.GroupLayout(pnlAdmin);
        pnlAdmin.setLayout(pnlAdminLayout);
        pnlAdminLayout.setHorizontalGroup(
            pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlAdminLayout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnlAdminLayout.createSequentialGroup()
                            .addComponent(lblGender)
                            .addGap(46, 46, 46)
                            .addComponent(cboGender, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlAdminLayout.createSequentialGroup()
                            .addComponent(lblBirthday)
                            .addGap(40, 40, 40)
                            .addComponent(txtBirthDate, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlAdminLayout.createSequentialGroup()
                            .addComponent(lblEmail)
                            .addGap(59, 59, 59)
                            .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlAdminLayout.createSequentialGroup()
                            .addComponent(lblAddress)
                            .addGap(43, 43, 43)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlAdminLayout.createSequentialGroup()
                            .addGap(60, 60, 60)
                            .addComponent(btnCreate, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(30, 30, 30)
                            .addComponent(btnRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(pnlAdminLayout.createSequentialGroup()
                            .addComponent(lblGroupName1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cboPermisson, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlAdminLayout.createSequentialGroup()
                            .addComponent(lblUserID)
                            .addGap(46, 46, 46)
                            .addComponent(txtUserID, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlAdminLayout.createSequentialGroup()
                            .addComponent(lblUserName)
                            .addGap(27, 27, 27)
                            .addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlAdminLayout.createSequentialGroup()
                            .addComponent(lblPassword)
                            .addGap(35, 35, 35)
                            .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlAdminLayout.createSequentialGroup()
                            .addComponent(lblConfirmPass, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(10, 10, 10)
                            .addComponent(txtConfirmPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlAdminLayout.createSequentialGroup()
                            .addComponent(lblGroupName)
                            .addGap(18, 18, 18)
                            .addComponent(cboGroupName, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlAdminLayout.createSequentialGroup()
                            .addComponent(lblGroupID)
                            .addGap(37, 37, 37)
                            .addComponent(txtGroupID, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlAdminLayout.createSequentialGroup()
                            .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lblFullname)
                                .addComponent(jLabel1)
                                .addComponent(jLabel2))
                            .addGap(33, 33, 33)
                            .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(txtFirstName)
                                .addComponent(txtLastName, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                                .addComponent(txtPhone)))))
                .addContainerGap(168, Short.MAX_VALUE))
        );
        pnlAdminLayout.setVerticalGroup(
            pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlAdminLayout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblUserID)
                    .addComponent(txtUserID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblUserName)
                    .addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblPassword)
                    .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblConfirmPass)
                    .addComponent(txtConfirmPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblGroupName)
                    .addComponent(cboGroupName, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblGroupID)
                    .addComponent(txtGroupID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblFullname)
                    .addComponent(txtFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(23, 23, 23)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblGroupName1)
                    .addComponent(cboPermisson, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cboGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblGender))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblBirthday)
                    .addComponent(txtBirthDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblEmail)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblAddress)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addGroup(pnlAdminLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnCreate, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(112, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(pnlAdmin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlAdmin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cboGroupNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboGroupNameActionPerformed
//        String GroupID = DataInteraction.getAnotherField("[Group]","[Group_Detail]", "GroupName", "GroupID", cboGroupName.getSelectedItem().toString());
//        txtGroupID.setText(GroupID);
    }//GEN-LAST:event_cboGroupNameActionPerformed

    private void btnCreateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCreateActionPerformed
//        if (!Validation.validateComponents(new JTextComponent[]{txtUserName, txtPassword, txtConfirmPassword, txtFirstName, txtLastName, txtPhone, txaAddress, txtBirthDate, txtEmail})) {
//            return;
//        }
        if (txtBirthDate.getText().trim().length() > 0) {
            if (!Validation.isDate(txtBirthDate.getText())) {
                Validation.showMessage("Date must in dd/MM/yyy format");
                txtBirthDate.setBackground(new Color(250, 255, 168));
                txtBirthDate.requestFocus();
                return;
            }
            if (Validation.convertStringToDate(txtBirthDate.getText()).compareTo(new Date(System.currentTimeMillis())) >= 0) {
                Validation.showMessage("Date must be before current time");
                txtBirthDate.setBackground(new Color(250, 255, 168));
                txtBirthDate.requestFocus();
                return;
            }
        }
        if (!txtPassword.getText().equals(txtConfirmPassword.getText())) {
            Validation.showMessage("Two password must be the same");
            txtPassword.setBackground(new Color(250, 255, 168));
            txtConfirmPassword.setBackground(new Color(250, 255, 168));
            txtConfirmPassword.requestFocus();
            return;
        }
        if (txtEmail.getText().trim().length() > 0) {
            if (!Validation.isValidEmail(txtEmail.getText())) {
                Validation.showMessage("Wrong email format");
                txtEmail.setBackground(new Color(250, 255, 168));
                txtEmail.requestFocus();
                return;
            }
        }
        if (Validation.isDuplicateValue("[User]", "UserName", txtUserName.getText())) {
            Validation.showMessage("User name has existed");
            txtUserName.setBackground(new Color(250, 255, 168));
            return;
        } else {
            txtUserName.setBackground(Color.white);
        }
        
        if(Validation.isValidPhoneNumber(txtPhone.getText())){
            Validation.showMessage("Phone number only accept value 0-9!!!");
            txtPhone.setBackground(new Color(250,255,168));
            txtPhone.requestFocus();
            return;
        }
        User userInsertTemp = getUser();
//        try {
//            userInsertTemp.setUserID(AdministrationInteraction.createNewUserId());
//            txtUserID.getText();
//        } catch (SQLException ex) {
//            ex.printStackTrace();
//        }
        String result = AdministrationInteraction.insertUser(userInsertTemp);
        new ShowMessageDialog(null, true, "Administrator account have been created!!!", ShowMessageDialog.MESSAGE);
        this.dispose();
//        refresh();
    }//GEN-LAST:event_btnCreateActionPerformed

    private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed
//        refresh();
    }//GEN-LAST:event_btnRefreshActionPerformed

    private void cboPermissonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboPermissonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cboPermissonActionPerformed

    private void txtUserIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtUserIDActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtUserIDActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCreate;
    private javax.swing.JButton btnRefresh;
    private javax.swing.JComboBox cboGender;
    private javax.swing.JComboBox cboGroupName;
    private javax.swing.JComboBox cboPermisson;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblAddress;
    private javax.swing.JLabel lblBirthday;
    private javax.swing.JLabel lblConfirmPass;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblFullname;
    private javax.swing.JLabel lblGender;
    private javax.swing.JLabel lblGroupID;
    private javax.swing.JLabel lblGroupName;
    private javax.swing.JLabel lblGroupName1;
    private javax.swing.JLabel lblPassword;
    private javax.swing.JLabel lblUserID;
    private javax.swing.JLabel lblUserName;
    private javax.swing.JPanel pnlAdmin;
    private javax.swing.JTextArea txaAddress;
    private javax.swing.JTextField txtBirthDate;
    private javax.swing.JPasswordField txtConfirmPassword;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtFirstName;
    private javax.swing.JTextField txtGroupID;
    private javax.swing.JTextField txtLastName;
    private javax.swing.JPasswordField txtPassword;
    private javax.swing.JTextField txtPhone;
    private javax.swing.JTextField txtUserID;
    private javax.swing.JTextField txtUserName;
    // End of variables declaration//GEN-END:variables
    Vector users = LoginInteraction.getUser();//thay getUserInformation()

//    private void fillTable() {
//        Vector title = new Vector();
//        title.add("User ID");
//        title.add("UserName");
//        title.add("Group");
//
//        Vector campaigns = LoginInteraction.readUser();
//        if (campaigns.size() > 0) {
//            tblAdministration.setModel(new DefaultTableModel(campaigns, title));
//            tblAdministration.getColumnModel().getColumn(0).setPreferredWidth(70);
//            tblAdministration.getColumnModel().getColumn(1).setPreferredWidth(100);
//            tblAdministration.getColumnModel().getColumn(2).setPreferredWidth(100);
//            tblAdministration.setDragEnabled(false);
//        }
//    }
//
//    private void refresh() {
//        users = LoginInteraction.getUserInformation();
//        fillTable();
//        Validation.setBlankField(new JTextComponent[]{txtUserID, txtUserName, txtPassword, txtConfirmPassword, txtFullName, txtEmail, txtBirthDate, araAddress});
//        cboGroupName.setSelectedIndex(0);
//        cboGender.setSelectedIndex(0);
//        btnCreate.setEnabled(true);
//    }

    // Method to get value from the form, and return a User object.
    private User getUser() {
        User user = new User();
        user.setUserID(txtUserID.getText());
        user.setUserName(txtUserName.getText());
        user.setPassword(txtPassword.getText());
        user.setFullName(txtFirstName.getText());
        user.setLastName(txtLastName.getText());
        user.setPhone(txtPhone.getText());
        user.setGender(cboGender.getSelectedItem().toString());
        user.setDateOfBirth(Validation.convertStringToDate(txtBirthDate.getText()));
        user.setAddress(txaAddress.getText());
        user.setEmail(txtEmail.getText());
        user.setGroupID(txtGroupID.getText());
        user.setGroupName(cboGroupName.getSelectedItem().toString());
        user.setPermission(cboPermisson.getSelectedItem().toString());

        return user;
    }
}
